package com.itheima02.day11;

import java.util.Comparator;
import java.util.Map;
import java.util.Set;
import java.util.TreeMap;

/**
 * @author 刘全
 * @date 2021/7/28
 */
public class Test2 {
    public static void main(String[] args) {
        TreeMap<Student, String> tm = new TreeMap<>(new Comparator<Student>() {
            @Override
            public int compare(Student o1, Student o2) {
                int result = o1.getAge()-o2.getAge();
                result = result == 0 ? o1.getName().compareTo(o2.getName()) : result;
                return result;
            }
        });
        Student stu1 = new Student("xiaopi", 23);
        Student stu2 = new Student("xiaowu", 22);
        Student stu3 = new Student("xiaotao", 22);
        tm.put(stu1, "常德");
        tm.put(stu2, "益阳");
        tm.put(stu3, "长沙");
        Set<Map.Entry<Student, String>> entries = tm.entrySet();
        for (Map.Entry<Student, String> entry : entries) {
            Student key = entry.getKey();
            String value = entry.getValue();
            System.out.println(key+"-----"+value);
        }
    }
}
